//
//  UIView+EV.m
//  LSYReader
//
//  Created by sam on 2018/3/29.
//  Copyright © 2018年 okwei. All rights reserved.
//

#import "UIView+EV.h"

@implementation UIView (EV)

- (CGPoint)ev_position
{
    return self.frame.origin;
}

-(CGSize)ev_size {
    return self.frame.size;
}

-(CGFloat)ev_left {
    return self.frame.origin.x;
}

-(CGFloat)ev_top {
    return self.frame.origin.y;
}

-(CGFloat)ev_right {
    return [self ev_left] + [self ev_width];
}

-(CGFloat)ev_bottom {
    return [self ev_top] + [self ev_height];
}

-(CGFloat)ev_width {
    return self.frame.size.width;
}

-(CGFloat)ev_height {
    return self.frame.size.height;
}

-(void)ev_setLeft:(CGFloat) left {
    CGRect frame = self.frame;
    frame.origin.x = left;
    self.frame = frame;
}

-(void)ev_setRight:(CGFloat) right {
    CGRect frame = self.frame;
    frame.origin.x = right - frame.size.width;
    self.frame = frame;
}

-(void)ev_setTop:(CGFloat) top {
    CGRect frame = self.frame;
    frame.origin.y = top;
    self.frame = frame;
}

-(void)ev_setBottom:(CGFloat) bottom {
    CGRect frame = self.frame;
    frame.origin.y = bottom - frame.size.height;
    self.frame = frame;
}

-(void)ev_setWidth:(CGFloat) width {
    CGRect frame = self.frame;
    frame.size.width = width;
    self.frame = frame;
}

-(void) ev_setHeight:(CGFloat) height {
    CGRect frame = self.frame;
    frame.size.height = height;
    self.frame = frame;
}

-(void) ev_setSize:(CGSize)size {
    CGRect frame = self.frame;
    frame.size = size;
    self.frame = frame;
}

-(void) ev_setPosition:(CGPoint)position {
    CGRect frame = self.frame;
    frame.origin.x = position.x;
    frame.origin.y = position.y;
    self.frame = frame;
}

+(id) ev_viewWithNib:(NSString*)nib owner:(id)owner {
    NSArray* array =[[NSBundle mainBundle] loadNibNamed:nib owner:owner options:nil];
    return array[0];
}

- (void)ev_adjustIntegralFrame
{
    self.frame = CGRectIntegral(self.frame);
}

-(void)ev_sizeToFitAutoLayout{
    CGSize size = [self systemLayoutSizeFittingSize:UILayoutFittingCompressedSize];
    [self ev_setSize:size];
}
@end
